﻿using System;
using System.Windows.Input;

namespace LogicStudio.Framework.UI.Comandos
{
    public class RelayCommand : ICommand
    {
        public event EventHandler CanExecuteChanged;

        Predicate<Object> _canExecute = null;
        Action<Object> _executeAction = null;

        public RelayCommand(Action<object> executeAction)
        {
            //_canExecute = true;
            _executeAction = executeAction;
        }


        public bool CanExecute(object parameter)
        {
            if (_canExecute != null)
                return _canExecute(parameter);

            return true;
        }

        public void UpdateCanExecuteState()
        {
            if (CanExecuteChanged != null)
                CanExecuteChanged(this, new EventArgs());
        }
        public void Execute(object parameter)
        {
            if (_executeAction != null)
                _executeAction(parameter); UpdateCanExecuteState();
        }
    }

}
